package cp3120.dao.remote;

import cp3120.dao.PurchaseDAO;
import cp3120.model.Purchase;
import cp3120.model.pricing.PricingStrategy;
import generic.net.client.Client;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: NecromancyBlack
 * Date: 26/05/2009
 * Time: 10:22:06 PM
 * To change this template use File | Settings | File Templates.
 */
public class RemotePurchaseDAO implements PurchaseDAO {
    private Client client;
    /**
     * Identifies this service
     */
    private static final String service = "RemotePurchaseService";

    /**
     * creates a RemotePurchaseDAO and sets the client
     * @param client the client this DAO is connected too
     */
    public RemotePurchaseDAO(Client client) {
        this.client = client;
    }

    /**
     * sends a request to the server to get a purchase
     * @param purchaseID the ID of the pruchase to be retreived
     * @return a purchase sent from the server
     */
    public Purchase getPurchase(int purchaseID) {
        return (Purchase)client.sendRequest(service, "getPurchase", purchaseID).getResponse().getPayload();
    }

    /**
     * sends a request to the server for a list of all purchases a specified user has made
     * @param userID The ID of the user who's purchases are to be retreived
     * @return a list of purchases sent from the server
     */
    public List<Purchase> getUserPurchases(int userID) {
        return (List<Purchase>)client.sendRequest(service, "getUserPurchases", userID).getResponse().getPayload();
    }

    /**
     * sends a request to the server to add a purchase
     * @param purchase the new purchase to be added
     * @return a boolean result from the server
     */
    public boolean addPurchase(Purchase purchase) {
        return (Boolean)client.sendRequest(service, "addPurchase", purchase).getResponse().getPayload();
    }

    public List<PricingStrategy> getPricingStrategys() {
        return (List<PricingStrategy>)client.sendRequest(service, "getPricingStrategys").getResponse().getPayload();
    }

    public boolean addPricingStrategy(PricingStrategy strategy) {
        return (Boolean)client.sendRequest(service, "addPricingStrategy", strategy).getResponse().getPayload();
    }

    public boolean removePricingStrategy(PricingStrategy strategy) {
        return (Boolean)client.sendRequest(service, "removePricingStrategy", strategy).getResponse().getPayload();
    }

    public boolean updatePricingStrategy(PricingStrategy strategy) {
        return (Boolean)client.sendRequest(service, "updatePricingStrategy", strategy).getResponse().getPayload();
    }
}
